package app.server.project.main.service.db.dao.statics;


import app.server.project.main.service.bo.dbquery.QueryActiveParam;
import app.server.project.main.service.db.entity.statics.StaticsActiveEntity;
import app.server.project.main.service.db.mapper.statics.StaticsActiveMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.Objects;

@Repository
public class StaticsActiveDao extends ServiceImpl<StaticsActiveMapper, StaticsActiveEntity> {

    public IPage<StaticsActiveEntity> getAll(IPage<StaticsActiveEntity> page, QueryActiveParam param) {
        var queryWrapper = Wrappers.<StaticsActiveEntity>lambdaQuery();
        if (Objects.nonNull(param.getStart())) {
            queryWrapper.ge(StaticsActiveEntity::getCreateTime, param.getStart());
        }
        if (Objects.nonNull(param.getEnd())) {
            queryWrapper.le(StaticsActiveEntity::getCreateTime, param.getEnd());
        }
        queryWrapper.orderByDesc(StaticsActiveEntity::getCreateTime);
        return this.page(page, queryWrapper);
    }
}
